import pytest
from .models import Account

@pytest.mark.django_db  # 允许访问数据库
class TestAccountModel:

    @pytest.fixture  # 使用 fixture 创建一个初始账户
    def account(self):
        return Account.objects.create(account_number="123456", balance=100.00)

    def test_account_creation(self, account):
        """测试账户创建"""
        assert account is not None  # 确保账户被成功创建

    def test_get_balance(self, account):
        """测试获取账户余额"""
        balance = account.get_balance()  # 获取账户余额
        assert balance == 100.00  # 验证余额是否正确

    def test_account_deposit(self, account):
        """测试存入金额"""
        account.deposit(50.00)  # 存入50.00
        assert account.get_balance() == 150.00  # 验证余额是否更新

    def test_account_withdraw(self, account):
        """测试取出金额"""
        account.withdraw(50.00)  # 取出50.00
        assert account.get_balance() == 50.00  # 验证余额是否更新

    def test_insufficient_funds(self, account):
        """测试取出超过余额的金额"""
        with pytest.raises(ValueError):
            account.withdraw(200.00)  # 试图取出超过余额的金额

    def test_deposit_negative_amount(self, account):
        """测试存入负金额的情况"""
        with pytest.raises(ValueError):
            account.deposit(-50.00)  # 试图存入负金额

    def test_withdraw_negative_amount(self, account):
        """测试取出负金额的情况"""
        with pytest.raises(ValueError):
            account.withdraw(-50.00)  # 试图取出负金额
